@model PageVM
@{
    var rows = Model.Rows as List<Gist>;

    //如果搜索只有一条，直接跳转
    var search = ViewContext.HttpContext.Request.Query["k"];
    if (rows.Count == 1 && Model.Pag.PageNumber == 1 && !string.IsNullOrEmpty(search))
    {
        ViewContext.HttpContext.Response.Redirect("/gist/code/" + rows.FirstOrDefault().GistCode);
    }

    var nickname = ViewData["Nickname"]?.ToString() ?? "Discover";
    ViewData["Title"] = $"{nickname} gists";
}

@if (rows.Count == 0)
{
    <h1 class="text-center my-5 py-5">咣</h1>
}
else
{
    @Html.Raw(Netnr.QuoteTo.Html("netnrmd.css,netnrmd.js"))
    <style>
        /*代码块显示语言*/
        pre code::after {
            position: absolute;
            top: 0;
            right: 0;
            font-size: 80%;
            padding: 3px 6px;
            content: attr(language);
            color: var(--sl-color-warning-600);
        }
    </style>

    <div class="container-fluid">
        <div class="row">
            <div class="col-12 p-4 pb-2">
                <span class="me-3 fs-4 align-middle"><b>@Model.Pag.Total.ToString("N0")</b> gists results</span>
                <sl-animation name="jello" duration="5000" play>
                    <sl-button href="/gist" size="small">Add gist</sl-button>
                </sl-animation>
            </div>
            @foreach (var item in rows)
            {
                <div class="col-lg-6 my-4 px-4">
                    <div class="text-nowrap">
                        <a class="me-2" href="/gist/user/@item.Uid">@item.Spare3</a>/
                        <a class="ms-1 fw-bold" href="/gist/code/@item.GistCode">@item.GistFilename</a>
                        <small class="ms-3 opacity-75 d-none d-sm-inline-block">@item.GistCreateTime.Value.ToString("yyyy-MM-dd HH:mm")</small>
                    </div>
                    <div class="my-2">
                        <span>@item.GistRemark</span>
                    </div>

                    <div class="markdown-body position-relative">
                        <pre class="mb-0"><code class="d-block" contenteditable language="@item.GistLanguage" style="min-height:14.5em">@item.GistContentPreview.TrimEnd(Environment.NewLine.ToCharArray()).TrimEnd('\r')</code></pre>
                        <a href="/gist/code/@item.GistCode" class="d-block text-center p-2">查看详情</a>
                    </div>
                </div>
            }
            <div class="col-12">
                <partial name="_PartialPaging" model="Model" />
            </div>
        </div>
    </div>

    <script>netnrmd.hljs.highlightAll()</script>
}